package com.gopay.scheduler.job;

import com.gopay.common.domain.cbrmb.CbRmbTranAssistDtl;
import com.gopay.scheduler.GopayBaseJob;
import com.gopay.scheduler.service.cbrmb.CbRmbCCBCheckOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author b.zou
 * @description
 * @class CbRmbCCBAutoCheckOrderJob
 * @date 2018.2.8
 */
public class CbRmbCCBAutoCheckOrderJob extends GopayBaseJob {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource(name = "cbRmbCCBCheckOrderService")
    private CbRmbCCBCheckOrderService cbRmbCCBCheckOrderService;

    @Override
    protected void doJobInternal() {
        logger.info("=====CbRmbCCBAutoCheckOrderJob START=====");
        try{
           List<CbRmbTranAssistDtl> list = cbRmbCCBCheckOrderService.getOrderList();
           if(null!=list&&list.size()>0){
               logger.info("跨境出款自动对账开始，对账笔数：{}", list.size());
               for (CbRmbTranAssistDtl dtl : list) {
                   try {
                       cbRmbCCBCheckOrderService.ccbCheckOrder(dtl);
                   }catch (Exception e){
                       logger.error("跨境出款自动对账异常，订单号：{},异常信息：{}", new Object[]{dtl.getGopayOrderId(),e});
                   }
               }
           }else{
               logger.info("没有跨境出款订单需要对账，对账任务结束");
           }
        }catch (Exception e){
            logger.error("跨境出款自动对账异常，异常信息：{}", e);
        }
        logger.info("=====CbRmbCCBAutoCheckOrderJob STOP=====");
    }
}
